package lp.xian.production.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lp.xian.production.vo.ProductionInventoryVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.production.domain.ProductInventory;
import lp.xian.production.service.IProductInventoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产损耗Controller
 *
 * @author ruoyi
 * @date 2023-07-05
 */
@RestController
@RequestMapping("/productinventory/productinventory")
public class ProductInventoryController extends BaseController
{
    @Autowired
    private IProductInventoryService productInventoryService;
    /**
     * 审核生产损耗
     */
    @PreAuthorize("@ss.hasPermi('productinventory:productinventory:audit')")
    @Log(title = "生产损耗", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult auditProductInvenory(@RequestBody ProductionInventoryVo productionInventoryVo)
    {
        return toAjax(productInventoryService.auditProductInvenory(productionInventoryVo));
    }

    /**
     * 审批生产损耗
     */
    @PreAuthorize("@ss.hasPermi('productinventory:productinventory:approver')")
    @Log(title = "生产损耗", businessType = BusinessType.UPDATE)
    @PutMapping("/approver")
    public AjaxResult approverProductInvenory(@RequestBody ProductionInventoryVo productionInventoryVo)
    {
        return toAjax(productInventoryService.approverProductInvenory(productionInventoryVo));
    }

    /**
     * 查询生产损耗列表
     */
    @PreAuthorize("@ss.hasPermi('productinventory:productinventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductInventory productInventory)
    {
        startPage();
        List<ProductInventory> list = productInventoryService.selectProductInventoryList(productInventory);
        return getDataTable(list);
    }

    /**
     * 导出生产损耗列表
     */
    @PreAuthorize("@ss.hasPermi('productinventory:productinventory:export')")
    @Log(title = "生产损耗", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductInventory productInventory)
    {
        List<ProductInventory> list = productInventoryService.selectProductInventoryList(productInventory);
        ExcelUtil<ProductInventory> util = new ExcelUtil<ProductInventory>(ProductInventory.class);
        util.exportExcel(response, list, "生产损耗数据");
    }

    /**
     * 获取生产损耗详细信息
     */
    @PreAuthorize("@ss.hasPermi('productinventory:productinventory:query')")
    @GetMapping(value = "/{productionInventoryId}")
    public AjaxResult getInfo(@PathVariable("productionInventoryId") Integer productionInventoryId)
    {
        return success(productInventoryService.selectProductInventoryByProductionInventoryId(productionInventoryId));
    }

    /**
     * 新增生产损耗
     */
    @PreAuthorize("@ss.hasPermi('productinventory:productinventory:add')")
    @Log(title = "生产损耗", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductInventory productInventory)
    {
        return toAjax(productInventoryService.insertProductInventory(productInventory));
    }

    /**
     * 修改生产损耗
     */
    @PreAuthorize("@ss.hasPermi('productinventory:productinventory:edit')")
    @Log(title = "生产损耗", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionInventoryVo productionInventoryVo)
    {
        return toAjax(productInventoryService.updateProductInventory(productionInventoryVo));
    }

    /**
     * 删除生产损耗
     */
    @PreAuthorize("@ss.hasPermi('productinventory:productinventory:remove')")
    @Log(title = "生产损耗", businessType = BusinessType.DELETE)
    @DeleteMapping("/{productionInventoryIds}")
    public AjaxResult remove(@PathVariable Integer[] productionInventoryIds)
    {
        return toAjax(productInventoryService.deleteProductInventoryByProductionInventoryIds(productionInventoryIds));
    }
}
